package com.xyzwps.lib.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

class SimpleTransactionContext implements TransactionContext {

    private final Connection conn;

    private final ResultSetToBean rs2b;

    SimpleTransactionContext(Connection conn, ResultSetToBean rs2b) {
        this.conn = conn;
        this.rs2b = rs2b;
    }

    @Override
    public ResultSetToBean rs2b() {
        return rs2b;
    }

    @Override
    public Statement createStatement() throws SQLException {
        return conn.createStatement();
    }

    @Override
    public PreparedStatement prepareStatement(String sql, boolean returnAutoGeneratedKeys) throws SQLException {
        return conn.prepareStatement(sql, returnAutoGeneratedKeys ? Statement.RETURN_GENERATED_KEYS : Statement.NO_GENERATED_KEYS);
    }

    @Override
    public PreparedStatement prepareStatement(String sql) throws SQLException {
        return conn.prepareStatement(sql);
    }

    @Override
    public void close() throws SQLException {
        conn.close();
    }
}
